#include "enemyplane.h"
#include "config.h"


EnemyPlane::EnemyPlane()
{
    //敌人资源加载
    int rand();
    int a= 1 + rand() % 4;
    if(a==5)m_enemy.load(ENEMY_PATH5);
    if(a==4)m_enemy.load(ENEMY_PATH4);
    if(a==3)m_enemy.load(ENEMY_PATH3);
    if(a==2)m_enemy.load(ENEMY_PATH2);
    if(a==1)m_enemy.load(ENEMY_PATH1);


    //敌人位置
    m_X = 0;
    m_Y = 0;

    //敌人状态
    m_Free = true;

    //敌人速度
    m_Speed = ENEMY_SPEED;

    //敌人矩形
    m_Rect.setWidth(m_enemy.width());
    m_Rect.setHeight(m_enemy.height());
    m_Rect.moveTo(m_X,m_Y);

}

void EnemyPlane::updatePosition()
{
    //空闲状态，不计算坐标
    if(m_Free)
    {
        return;
    }

    m_Y += m_Speed;
    m_Rect.moveTo(m_X,m_Y);

    if(m_Y >= GAME_HEIGHT)
    {
        m_Free = true;
    }
}

